<template>
  <el-row justify="end">
    <el-tooltip class="item" effect="dark" content="快捷键提示" placement="top">
      <el-button circle @click="isVisible = true">
        <icon-svg iconName="qm" :w="20" :h="20" />
      </el-button>
    </el-tooltip>
    <el-tooltip class="item" effect="dark" content="撤销" placement="top">
      <el-button circle @click="revocation()" :disabled="checkUndoDisable">
        <el-icon :size="20">
          <refresh-left />
        </el-icon>
      </el-button>
    </el-tooltip>
    <el-tooltip class="item" effect="dark" content="重做" placement="top">
      <el-button circle @click="reform()" :disabled="checkRedoDisable">
        <el-icon :size="20">
          <refresh-right />
        </el-icon>
      </el-button>
    </el-tooltip>
    <el-tooltip class="item" effect="dark" content="重置" placement="top">
      <el-button circle @click="reset()">
        <el-icon :size="20">
          <refresh />
        </el-icon>
      </el-button>
    </el-tooltip>
    <el-dialog
      title="快捷键操作"
      v-model="isVisible"
      append-to-body
      :custom-class="'shortcut-dialog'"
      :width="'400px'"
    >
      <div
        class="px-3 mb-1 flex justify-between"
        v-for="item in tipList"
        :key="item.shortcut"
      >
        <span class="text">{{ item.text }}</span>
        <span class="bold">{{ item.shortcut }}</span>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="isVisible = false">确认</el-button>
        </div>
      </template>
    </el-dialog>
  </el-row>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from "vue";
import dataOperation, { operationText } from "@/plugins/dataOperations.ts";
import { useStore } from "vuex";
import { IGlobalDataProps } from "@/store/index.ts";
import {
  CHECK_UNDO_DISABLE,
  CHECK_REDO_DISABLE,
  UNDO,
  REDO,
  EDITOR_RESET,
} from "@/utils/Const";

export default defineComponent({
  setup() {
    const store = useStore<IGlobalDataProps>();
    let isVisible = ref(false);
    let tipList = ref(Object.values(operationText));
    let checkUndoDisable = computed<boolean>(
      () => store.getters[`editor/${CHECK_UNDO_DISABLE}`]
    );
    let checkRedoDisable = computed<boolean>(
      () => store.getters[`editor/${CHECK_REDO_DISABLE}`]
    );
    const currentId = computed(() => store.state.editor.currentId);
    const operations = dataOperation(currentId);
    // 撤销
    let revocation = () => {
      store.commit(`editor/${UNDO}`);
    };
    // 重做
    let reform = () => {
      store.commit(`editor/${REDO}`);
    };

    // 重置
    let reset = () => {
      operations.reset();
    };

    return {
      tipList,
      isVisible,
      revocation,
      reform,
      reset,
      checkUndoDisable,
      checkRedoDisable,
    };
  },
});
</script>

<style lang="scss" scoped>
.text {
  color: rgba(0, 0, 0, 0.45);
}
.bold {
  color: #1890ff;
}
</style>
<style lang="scss">
.shortcut-dialog {
  .el-dialog__header {
    border-bottom: 1px solid #eeeeee;
  }
}
</style>
